package com.huang.servicebase.execptionhandler;




import com.hunag.utils.R;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//全局异常
@Slf4j
@ControllerAdvice
public class GlobaExecption {
    //指定什么异常执行该方法
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.error().message("执行了全局异常");
    }


    //自定义异常 需手动抛出
    @ExceptionHandler(huangException.class)
    @ResponseBody
    public R error(huangException e){
        log.error(e.getMsg());//打印出现的异常
        e.printStackTrace();
        return R.error().code(e.getCode()).message(e.getMsg());

    }
}
